
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>部署nginx服务 · docker swarm实践文档</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Carey">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://carey.akhack.com" target="_blank" class="custom-link">Home</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    基础环境
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../base_book/环境介绍.html">
            
                <a href="../base_book/环境介绍.html">
            
                    
                    环境介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../base_book/环境准备.html">
            
                <a href="../base_book/环境准备.html">
            
                    
                    基础准备
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../base_book/安装docker.html">
            
                <a href="../base_book/安装docker.html">
            
                    
                    安装 docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../base_book/compose_file.html">
            
                <a href="../base_book/compose_file.html">
            
                    
                    compose file文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../base_book/registry仓库管理.html">
            
                <a href="../base_book/registry仓库管理.html">
            
                    
                    registry管理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    swarm 群集
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../swarm_book/创建群集.html">
            
                <a href="../swarm_book/创建群集.html">
            
                    
                    创建群集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../swarm_book/portainer.html">
            
                <a href="../swarm_book/portainer.html">
            
                    
                    swarm管理工具Portainer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../swarm_book/群集监控.html">
            
                <a href="../swarm_book/群集监控.html">
            
                    
                    cAdvisor InfluxDB Grafana搭建监控平台
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../swarm_book/telegraf.html">
            
                <a href="../swarm_book/telegraf.html">
            
                    
                    Telegraf监控容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../swarm_book/Chronograf.html">
            
                <a href="../swarm_book/Chronograf.html">
            
                    
                    Chronograf显示监控数据
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    swarm service
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.4.1" data-path="nginx.html">
            
                <a href="nginx.html">
            
                    
                    部署nginx服务
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    swarm stack
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../swarm_stack/lnmpwordpress.html">
            
                <a href="../swarm_stack/lnmpwordpress.html">
            
                    
                    部署wordpress
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../swarm_stack/build_eureka.md">
            
                <span>
            
                    
                    部署eureka
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >部署nginx服务</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x521B;&#x5EFA;&#x4E00;&#x4E2A;nginx&#x670D;&#x52A1;">&#x521B;&#x5EFA;&#x4E00;&#x4E2A;nginx&#x670D;&#x52A1;</h1>
<pre><code>$ docker service create --replicas 3 --name nginx -p 80:80 nginx
kwsc18x629dg7bykpf865p317
overall progress: 3 out of 3 tasks
1/3: running   [==================================================&gt;]
2/3: running   [==================================================&gt;]
3/3: running   [==================================================&gt;]
verify: Service converged
</code></pre><ul>
<li><code>--replicas</code>&#x521B;&#x5EFA;&#x7684;&#x526F;&#x672C;&#x6570;&#x91CF;</li>
</ul>
<h1 id="&#x67E5;&#x770B;&#x8FD0;&#x884C;&#x7684;&#x670D;&#x52A1;">&#x67E5;&#x770B;&#x8FD0;&#x884C;&#x7684;&#x670D;&#x52A1;</h1>
<pre><code>$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
kwsc18x629dg        nginx               replicated          3/3                 nginx:latest        *:80-&gt;80/tcp
</code></pre><p>&#x56E0;&#x4E3A;&#x4F7F;&#x7528;&#x4E86;-p&#x66B4;&#x9732;&#x7AEF;&#x53E3;&#xFF0C;swarm&#x4E3A;&#x4E86;&#x540E;&#x7EED;&#x6269;&#x5C55;&#x548C;&#x4FBF;&#x4E8E;&#x7EF4;&#x62A4;&#x5728;&#x7FA4;&#x96C6;&#x6240;&#x6709;&#x4E3B;&#x673A;&#x4E0A;&#x90FD;&#x5F00;&#x653E;&#x4E86;80&#x7AEF;&#x53E3;&#x3002;&#x73B0;&#x5728;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7FA4;&#x96C6;&#x5185;&#x4EFB;&#x4F55;&#x4E00;&#x53F0;&#x53BB;&#x8BBF;&#x95EE;nginx&#x670D;&#x52A1;</p>
<h1 id="&#x67E5;&#x770B;&#x670D;&#x52A1;&#x4FE1;&#x606F;">&#x67E5;&#x770B;&#x670D;&#x52A1;&#x4FE1;&#x606F;</h1>
<pre><code>$ docker service inspect --pretty nginx

ID:        kwsc18x629dg7bykpf865p317
Name:        nginx
Service Mode:    Replicated
 Replicas:    3
Placement:
UpdateConfig:
 Parallelism:    1
 On failure:    pause
 Monitoring Period: 5s
 Max failure ratio: 0
 Update order:      stop-first
RollbackConfig:
 Parallelism:    1
 On failure:    pause
 Monitoring Period: 5s
 Max failure ratio: 0
 Rollback order:    stop-first
ContainerSpec:
 Image:        nginx:latest@sha256:d0468eaec1ef818af05f85ac00e484fd5a2ae75dd567dc9f7ccf5f68a60351fb
Resources:
Endpoint Mode:    vip
Ports:
 PublishedPort = 80
  Protocol = tcp
  TargetPort = 80
  PublishMode = ingress
</code></pre><ul>
<li><code>--pretty</code>&#x4EE5;&#x4FBF;&#x4E8E;&#x67E5;&#x9605;&#x7684;&#x683C;&#x5F0F;&#x663E;&#x793A;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;json&#x683C;&#x5F0F;</li>
</ul>
<h1 id="&#x6269;&#x7F29;&#x5BB9;&#x670D;&#x52A1;">&#x6269;/&#x7F29;&#x5BB9;&#x670D;&#x52A1;</h1>
<pre><code>$ docker service scale nginx=5
</code></pre><h1 id="&#x6EDA;&#x52A8;&#x66F4;&#x65B0;">&#x6EDA;&#x52A8;&#x66F4;&#x65B0;</h1>
<pre><code># &#x521B;&#x5EFA;&#x4E00;&#x4E2A;redis&#x670D;&#x52A1;
docker service create \
  --replicas 3 \
  --name redis \
  --update-delay 10s \
  redis:3.0.6

# &#x66F4;&#x65B0;redis&#x670D;&#x52A1;
docker service update --image redis:3.0.7 redis
</code></pre><ul>
<li><code>--update-delay 10s</code>&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x8282;&#x70B9;&#x95F4;&#x9694;&#x65F6;&#x95F4;10s</li>
</ul>
<p><strong>&#x66F4;&#x65B0;&#x6267;&#x884C;&#x8FC7;&#x7A0B;&#xFF1A;</strong></p>
<ul>
<li>&#x505C;&#x6B62;&#x7B2C;&#x4E00;&#x9879;&#x4EFB;&#x52A1;&#x3002;</li>
<li>&#x4E3A;&#x5DF2;&#x505C;&#x6B62;&#x7684;&#x4EFB;&#x52A1;&#x8BA1;&#x5212;&#x66F4;&#x65B0;&#x3002;</li>
<li>&#x542F;&#x52A8;&#x66F4;&#x65B0;&#x4EFB;&#x52A1;&#x7684;&#x5BB9;&#x5668;&#x3002;</li>
<li>&#x5982;&#x679C;&#x4EFB;&#x52A1;&#x66F4;&#x65B0;&#x8FD4;&#x56DE;RUNNING&#xFF0C;&#x8BF7;&#x7B49;&#x5F85;&#x6307;&#x5B9A;&#x7684;&#x5EF6;&#x8FDF;&#x65F6;&#x95F4;&#xFF0C;&#x7136;&#x540E;&#x5F00;&#x59CB;&#x4E0B;&#x4E00;&#x4E2A;&#x4EFB;&#x52A1;&#x3002;</li>
<li>&#x5982;&#x679C;&#x5728;&#x66F4;&#x65B0;&#x8FC7;&#x7A0B;&#x4E2D;&#x7684;&#x4EFB;&#x4F55;&#x65F6;&#x95F4;&#x4EFB;&#x52A1;&#x8FD4;&#x56DE;FAILED&#xFF0C;&#x8BF7;&#x6682;&#x505C;&#x66F4;&#x65B0;&#x3002;</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"部署nginx服务","level":"1.4.1","depth":2,"next":{"title":"swarm stack","level":"1.5","depth":1,"ref":"","articles":[{"title":"部署wordpress","level":"1.5.1","depth":2,"path":"swarm_stack/lnmpwordpress.md","ref":"swarm_stack/lnmpwordpress.md","articles":[]},{"title":"部署eureka","level":"1.5.2","depth":2,"path":"swarm_stack/build_eureka.md","ref":"swarm_stack/build_eureka.md","articles":[]}]},"previous":{"title":"swarm service","level":"1.4","depth":1,"ref":"","articles":[{"title":"部署nginx服务","level":"1.4.1","depth":2,"path":"service_book/nginx.md","ref":"service_book/nginx.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["emphasize","alerts","code","-lunr","-search","search-plus","splitter"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"emphasize":{},"splitter":{},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"alerts":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","author":"Carey","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"docker swarm实践文档","language":"zh-hans","links":{"sidebar":{"Home":"http://carey.akhack.com"}},"gitbook":"*"},"file":{"path":"service_book/nginx.md","mtime":"2018-07-06T03:01:13.282Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-12-04T03:25:36.834Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

